// What we have here is some ajax and some jQuery contact form

$(document).ready(function(){
	
	$('form#contactForm .submit').click(function(){

		$('#contactForm .error').removeClass();
		var name = $('input#name').val();
		if (name == "" || name == " " || name == "Name") {
			$('input#name').attr('placeholder', 'You forgot your name!'); 
		    $('input#name').addClass("error");
		    return false;
		}
		
		var email_test = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		var email = $('input#email').val();
		if (email == "" || email == " ") {
		   $('input#email').addClass("error");
		   $('input#email').attr('placeholder', 'You forgot your email!'); 
		   return false;
		} else if (!email_test.test(email)) {
		   $('input#email').addClass("error");
		   $('input#email').attr('value', ''); 
		   $('input#email').attr('placeholder', "You're doing it wrong."); 
		   
		   return false;
		}
		
		var message = $('#message').val();
		if (message == "" || message == " " || message == "Message") {
			$('#message').addClass("error");
			$('#message').attr('placeholder', "Empty message boxes are so sad and lonely."); 
		    return false;
		}
		
		var data_string = $('form#contactForm').serialize();

		$.ajax({
		    type:       "POST",
		    url:        "contact.php",
		    data:       data_string,
		    success:    function() {

		$('form#contactForm').slideUp('fast').before('<div id="success"></div>');
		$('#success').html("<h3>Huge Success</h3><p>It's hard to overstate how much your e-mail was sent.</p>").slideDown(9000);

		    }//end success function


		}) //end ajax call

		return false;


	}) //end click function
	
	var current_data = new Array();

	$('.clear').each(function(i){
		$(this).removeClass('clear').addClass('clear'+i);
		current_data.push($(this).val());

		$(this).focus(function(){
			if($(this).val() == current_data[i]) {
				$(this).val('');
			}
		});
		$(this).blur(function(){
			var stored_data = current_data[i];
			if($(this).val()==''){
				$(this).val(stored_data);
			}
		})
	});
})

// Prettyness for our static nav. Turns on and off current states based on the scrollbar's relation to
// a div's height from the top, yo.

$(window).scroll(function () { 
	var documentScrollTop = $(document).scrollTop();
	var viewportHieght = $(window).height();
	var minTop = documentScrollTop;
	var maxTop = documentScrollTop + viewportHieght;
	
  	if($(window).scrollTop() <= $("#manifesto").offset().top){
  		$("#scrollNav ul").fadeOut();
  	}
     if($(window).scrollTop() >= $("#manifesto").offset().top){
  		$("#scrollNav ul").fadeIn();
		$("#scManifesto").siblings(".current").removeClass("current");
		$("#scManifesto").addClass("current");
		

  	}
	if($(window).scrollTop() >= $("#evidence").offset().top){
		$("#scEvidence").siblings(".current").removeClass("current");
		$("#scEvidence").addClass("current");
		
  	}
	if($(window).scrollTop() >= $("#rapSheet").offset().top){
		$("#scRap").siblings(".current").removeClass("current");
		$("#scRap").addClass("current");
  	}
	if($("#footer img").offset().top > minTop && $("#footer img").offset().top < maxTop){
		$("#sContact").siblings(".current").removeClass("current");
		$("#sContact").addClass("current");
  	}
});
	
	// For the local scrolling
	
		$(document).ready(function() {
		$.localScroll({
			offset:1 
		});
	});
	
	// Twitter plugin controls!
	
	    jQuery(function($){
        $(".tweet").tweet({
            username: "jdwolff",
            join_text: "auto",
            avatar_size: 0,
            count: 4,
            auto_join_text_default: "jdwolff said,", 
            auto_join_text_ed: "jdwolff",
            auto_join_text_ing: "jdwolff was",
            auto_join_text_reply: "jdwolff replied to",
            auto_join_text_url: "jdwolff was checking out",
            loading_text: "loading tweets..."
        });
    });

	// That's just the smell of my soft, sensual...flexslider.
	$(window).load(function() {
				$('.flexslider').flexslider({
				  animation: "slide",
				  controlsContainer: ".flexslider"
			  });
			});
	
	// Last, but not least, let's get fit in here. Fit text. HIYO!
	$("h1.ft, aside.surivalKit div.wrap h1").fitText(1.2, { minFontSize: 30, maxFontSize: '47px' });
	$("h3.ft").fitText(2, { minFontSize: 14, maxFontSize: '23px' });
	$("ul#kitContainer.clearfix li.clearfix").fitText(1.2, { minFontSize: 23, maxFontSize: '47px' });
